home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: What should be returned?
- Date: 19 Jan 1996 22:44 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <19JAN199622440915@erich.triumf.ca>
- References: <4dj8pv$cjd@eng_ser1.erg.cuhk.hk> <DLEvrv.K85@freenet.durham.org>
- NNTP-Posting-Host: erich.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <DLEvrv.K85@freenet.durham.org>, cschmidt@freenet.durham.org (Chris Schmidt) writes...
- >the CAReLess boy (phsung@cs.cuhk.hk) wrote:
-
- >: It's said that the function main must return an integer value
- >: but I just don't know what value should be returned. Also, if I quit
- >: main by exit(), what's the use of the return value?
-
- >I myself am just starting to learn this stuff too, but from what I have
- >read so far.. if you do not require an exit value from the program use:
- >
- >void main(void)
-
- You had better read a little further (but not in Schildt's books...)
-
- In spite of many introductory books to the contary, the C standard _requires_
- that main() return an int. In many operating systems, this return value can be
- tested to determine something about the exit status of a program. Under
- MS-DOs, this is done in batch files using "if errorlevel", where errorlevel is
- the value returned from main() (or returned by exit()). Some programs that
- call others, such as Make, and compiler IDEs, use this value to determine
- whether or not to continue with a process.
-
- Under DOS, and probably unix, it is up to the user, or a program such as make,
- to test this value - the operating system doesn't care itself, but some other
- operating systems may take a more direct interest in the return value.
-
- stdlib.h #defines EXIT_SUCCESS and EXIT_FAILURE for use as portable return
- codes.
-
-
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
-
-